home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / wgt35.zip / SCROLL.DOC < prev    next >
Text File  |  1993-01-28  |  13KB  |  329 lines

  1.           WGT Multidirectional Scrolling Library
  2.            Copyright 1993 Chris Egerter
  3.  
  4. Multidirectional Scrolling: Introduction
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. Multidirectional scrolling is a complex task, and will be difficult
  7. to understand when you first use it. If something doesn't work,
  8. don't give up. There is probably a simple reason for it.
  9. This documentation does not tell you everything, such as
  10. how to use the commands together. Refer to the example programs
  11. for practical use of these commands.
  12.  
  13.     Games which involve scrolling are usually impressive.
  14. They are usually hard to program as well. With WGT v3.5, scrolling
  15. is built in, and you do not need to know any of the technical details.
  16.     When scrolling is used, you need to make an area which will be
  17. scrolled around in the window. This area is called a map. A map is made
  18. of tiles. Tiles are simply pieces of graphics that can be placed together
  19. like a jigsaw puzzle, forming a much larger picture. Each tile is always
  20. a graphic image which is 16x16 pixels. These images are created with
  21. the WGT Sprite Creator and saved as sprite files. Future versions of WGT
  22. will probably allow you to change the size of the tiles.
  23.     A map maker is available, which will allow you to visually design
  24. a map or world for your game to use. This is where you get to fit
  25. the pieces of the puzzle together. A map can be a maximum of 320
  26. tiles wide, and 200 tiles high. You will probably never use a map
  27. that big, since it would take a while to design it. Most commercial
  28. games don't even come close to maps this size.
  29. The largest map is equal to 5120 pixels across, and 3200 pixels down.
  30. That would be equal to 256 full VGA screens!
  31.  
  32. There are some numbers you should remeber when dealing with map and objects.
  33. Maps can be 320 by 200 tiles, and hold 200 tile types. 1000 Objects can on
  34. the map at once, and 1000 sprites can be held in a sprite file.
  35.  
  36.  
  37.     Objects are shown over the background while it scrolls. These are
  38. made from the sprite creator too. The objects will be your main character
  39. and all of the opponents which live in the world you've created.
  40.  
  41. A simple program which loads in your tiles,map, and objects, scrolls
  42. the around the screen using the keyboard, would be under 5k for the
  43. source code!
  44.  
  45. Tile type data simply assigns a number for each tile. You can set these
  46. numbers from the map maker. For example, if tiles 1-5 are solid walls,
  47. you can set their types to 1, meaning there is a obstacle in that spot.
  48. If tiles 6-30 are open spaces and the player can move through them, you
  49. can set their types to 0, meaning there is nothing at that spot.
  50. These are just suggestions. You can make many different tiles with
  51. different types, and design your program to react differently with each
  52. type of tile.
  53.     It will also help if you put all the solid tiles together
  54. so you can access them with an if statement.
  55.   eg. If ((tile>40) & (tile<70)) you_hit_a_wall();
  56.  
  57. Planning ahead will save you some programming time. Once you draw the
  58. tiles with the sprite creator and design the map files, it will be hard
  59. to switch the tiles around. Think about this BEFORE you start drawing
  60. your tiles.
  61.  
  62.  
  63. Two different coordinate systems are used with the four way scrolling.
  64. They are:
  65.  
  66.     Map coordinates: Block increments (16 pixels)
  67.             To convert a map coordinate to a world coordinate,
  68.             multiply by 16.
  69.             These are the same coordinates used in the World
  70.             Editor.
  71.  
  72.     World coordinates: Pixel increments (1 pixel)
  73.             Divide by 16 to convert to map coordinates.
  74.             Used by scrollsprites (wobject).
  75.  
  76.  
  77.  
  78.  
  79. Available functions:
  80.  
  81. -----------------------------------------------------------------------------
  82. wgtmap wloadmap(char *filename);
  83.  
  84.     Loads a map previously created with the WGT World Editor.
  85. NOTE: You cannot load in more than one map at once. Future versions will
  86. allow this.
  87.  
  88. Returns: NULL if map could not be loaded
  89.  
  90. Example use:
  91.      #include <wgt.h>
  92.      #include <scroll.h>
  93.      wgtmap mymap;
  94.  
  95.      void main(void)
  96.      {
  97.      mymap=wloadmap("gamemap.wmp");
  98.      }
  99.  
  100. Variables set:
  101.  
  102. int mapwidth,mapheight:  Width and height of map (in blocks) 
  103.  
  104.  
  105. -----------------------------------------------------------------------------
  106. void wfreemap(wgtmap mymap);
  107.  
  108.     Frees a map previously loaded with wloadmap.
  109.  
  110.  
  111. -----------------------------------------------------------------------------
  112. void winitscroll(int window_x_size,int window_y_size);
  113.  
  114.     Initializes the scrolling window. Should be called after loading
  115. the map file.  The window size is defined by window_x_size (2 to 17) and
  116. window_y_size (2 to 10) ,which are the number of 16*16 blocks across and
  117. down the window.
  118.  
  119.     eg.  winitscroll(17,10); will set a window 17 blocks in width,
  120. and 10 blocks in height. Therefore the actual width and height would
  121. be 272 by 160 (17*16 by 10*16).
  122.  
  123. After calling this procedure, the following variables are set:
  124.  
  125. int windowminx,windowminy: top left corner of window (always 0)
  126. int windowmaxx,windowmaxy: bottom right corner (width and height of window)
  127. block scroll1,scroll2:   two virtual screens needed for scrolling work (128K!)
  128.  
  129. -----------------------------------------------------------------------------
  130. void wshowwindow(int posx,int posy ,wgtmap mymap);
  131.  
  132. Begins scrolling at posx,posy as the top left corner of the window.
  133. Posx and Posy are the map coordinates used in the Map Maker.
  134. Use this at the beginning of you program, and when you need to 'warp'
  135. to another place on the map instantly.
  136.  
  137. Variables set:
  138. int worldx,worldy;  World coordinates of upper left corner of window.
  139.         These are updated every time you scroll, for location
  140.         references.
  141.         Set to posx*16,posy*16 when wshowwindow is called.
  142.  
  143. -----------------------------------------------------------------------------
  144. void installkbd(void);
  145.  
  146. Install the keyboard interrupt.  This lets you control the keyboard
  147. precisely, and is able to track which keys are being held down at once.
  148. It can handle any number and any combination of keys.
  149. See the example files for demonstration of this procedure.
  150.  
  151. Note: You cannot use ordinary keyboard routines when this is
  152. installed (getch(), scanf(), etc).
  153.  
  154.  
  155.  
  156. -----------------------------------------------------------------------------
  157. void uninstallkbd(void);
  158.  
  159. Removes the keyboard routine.
  160.  
  161.  
  162.  
  163. -----------------------------------------------------------------------------
  164. void wscrollwindow(int x_speed,int y_speed, wgtmap mymap);
  165.  
  166. Scrolls the window in the direction indicated by x_speed and y_speed.
  167. X_speed and y_speed must be no greater than 16.
  168.  
  169. Must be called continuosly to update the display.
  170.  
  171.  
  172.  
  173. -----------------------------------------------------------------------------
  174. int wgetworldblock(int posx,int posy,wgtmap mymap);
  175.  
  176. Returns the number of the block at posx,posy. (world coordinates)
  177. Used mainly for collision detection with wobjects and walls.
  178. If you want to use the map coordinates, multiply them by 16.
  179. This command uses world coordinates to make it easier to check
  180. where a wobject is.
  181.  
  182.  
  183. -----------------------------------------------------------------------------
  184. void wputworldblock(int posx,int posy ,int blocknum,wgtmap mymap);
  185.  
  186. Changes the block at posx,posy (world coordinates), to blocknum.
  187. Used for modifying the map, eg. Opening a door.
  188.  
  189.  
  190.  
  191. -----------------------------------------------------------------------------
  192. void wcopyscroll(int x,int y);
  193.  
  194. Copies the scrollwindow to the visual screen at x,y.
  195. You must use this to show the scrolling window after calling
  196. wscrollwindow.
  197.  
  198.  
  199.  
  200. -----------------------------------------------------------------------------
  201. void wshowobjects();
  202.  
  203. Shows all objects (up to 1000 possible) on the world.
  204. Call this between wscrollwindow, and wcopyscroll to draw the background on,
  205. draw the objects, and finally copy everything to the visual screen.
  206.  
  207. typedef struct {
  208.     char on;
  209.     int x;
  210.     int y;
  211.     unsigned int num;
  212.     } scrollsprites;
  213.  
  214. The scrollsprites structure used is:
  215. extern scrollsprites wobject[1001];
  216.  
  217. int numsprites: tells the maximum sprite drawn
  218. int spritewidth[1001],spriteheight[1001]: width and height of all objects
  219.     (used for wshowobjects or your own needs)
  220.  
  221. To make your game as fast as possible, you should make your own
  222. wshowobjects routine, and make the objects move when they are on the
  223. screen. Here is the code for the wshowobjects routine so you can
  224. modify it for speed:
  225.  
  226. void wshowobjects(void)
  227. {
  228. int i;
  229. wsetscreen(scroll1);
  230. wclip(0,0,windowmaxx,windowmaxy);
  231. for (i=0; i<=numsprites; i++)
  232.  {
  233.  if ((wobject[i].on==1) &
  234.     (sprites[wobject[i].num] !=NULL))
  235.    {
  236.    if ((wobject[i].x<worldx+windowmaxx) &
  237.       (wobject[i].y<worldy+windowmaxy) &
  238.       (wobject[i].x+spritewidth[wobject[i].num]>worldx) &
  239.       (wobject[i].y+spriteheight[wobject[i].num]>worldy))
  240.       {
  241.       // insert your code for moving objects here!
  242.       wputblock(wobject[i].x-worldx,wobject[i].y-worldy,sprites[wobject[i].num],1);
  243.       }
  244.    }
  245.  }
  246. }
  247.  
  248.  
  249.  
  250.  
  251. -----------------------------------------------------------------------------
  252. void wendscroll(void);
  253.  
  254. Closes the scrolling window and shuts down the scrolling.
  255.  
  256.  
  257.  
  258. -----------------------------------------------------------------------------
  259. void wsavemap(char *filename,wgtmap mymap)
  260.  
  261. Saves a WGT map file. Mainly used for saving a game while playing.
  262. Other variables needed for saving a game can be added to the end of
  263. this file after saving it.
  264.  
  265.  
  266.  
  267.  
  268. Multidirectional Scrolling: The Steps Needed for Success
  269. --------------------------------------------------------
  270.  
  271.     Making a game with scrolling requires some planning
  272. before you jump right in and start programming. Through experience with
  273. using WGT, here are my suggestions for creating a successful game.
  274.  
  275. 1. Draw the tiles and objects first.  Tiles should be grouped together
  276.    for easier programming later. Types should be used with the map
  277.    maker, so you don't need to have an if statement for every type
  278.    of tile. Leave spaces between each group of tiles in case you
  279.    need to add more later.
  280.    DO NOT make a map file if your tiles are not organized well.
  281.    If you change the number of a tile, the map will change as well,
  282.    and there is no easy way of correcting it, besides of redrawing
  283.    each spot with the new number.
  284.  
  285.    Objects should be drawn in sequence so you can use a simple
  286.    loop counter to animate through them. This is much easier than
  287.    skipping around in the sprite file to make an object animate.
  288.    As well, objects should be lined up correctly, so that when you
  289.    animate it, it will not have to move a few pixels to match
  290.    the previous object shown.
  291.  
  292. 2. Make a map file using the map maker. Set the tile types, and
  293.    leave the objects for now. Objects should be added after you have
  294.    programmed how the main character will interact with the map.
  295.    If you are using more than 1 map in a game, use a number in their
  296.    file extension. If you are using the same tiles for each map,
  297.    save the types from the original and load them back into the new map.
  298.    This will save you from typing in the types for every tile again.
  299.  
  300. 3. Now that you have the tiles,objects, and maps drawn, start
  301.    programming the basic routines which handles the main character's
  302.    interaction with the map background. This is where you need to
  303.    check where the character is, and decide if he/she is falling,
  304.    hitting a wall, or whatever your program needs.
  305.    Look at the example files for ideas on how to check where the
  306.    character is on the map.  You will need to use wgetworldblock
  307.    to find out what you are standing on.
  308.    Make the character move around on the map by running, jumping,
  309.    or other means of transportation. Allow the character to pick
  310.    up items, open doors, or shoot something.
  311.  
  312. 4. After you've got the character living happily within the map,
  313.    add in some bad guys by using the object placement within the map
  314.    maker. Placing them is one thing, making them react with the map
  315.    is another. You must make sure they can move around alright as
  316.    well, and not run through any walls or get stuck somewhere.
  317.    Only move the objects if they are on the screen. This will save
  318.    a lot of time since you don't need to check for walls around
  319.    them. When you get near them, they will start moving around
  320.    and be a threat.
  321.  
  322. 5. Ok. You should have the main character and the bad guys moving
  323.    around within the map.  Design the characters to react with
  324.    each other now, and detect collisions between them.
  325.  
  326. 6. Put on the final touches and send it to your friends!
  327.  
  328.  
  329.